//var prefixUrl="http://192.168.1.100:8080/Chefu/server/";//"http://192.168.51.231:8080/Chefu/server/";
//var serverUrl="http://120.25.102.118/as_carter/gateWay/pubCtrl.do";
var testUrl="http://www.chefuapp.com/epg/gateWay/pubCtrl.do";
// var
 //var testUrl="http://183.239.137.71:9837/Chefu/server/userLogin!dispatchAction.action";
// var
// testUrl="http://192.168.51.231:8080/Chefu/server/userLogin!dispatchAction.action";
// var
// testUrl="http://172.16.3.126:8080/Chefu/server/userLogin!dispatchAction.action";
// var
// testUrl="http://192.168.1.126:8080/Chefu/server/userLogin!dispatchAction.action";
// var
// testUrl="http://192.168.0.101:8080/Chefu/server/userLogin!dispatchAction.action";
var uploadUrl="http://www.chefuapp.com/epg/gateWay/uploadFile.do";
// var
// uploadUrl="http://192.168.0.126:8080:8080/Chefu/server/userLogin!dispatchAction.action";
(function($) {
	$.fn.serializeJson = function() {
		var serializeObj = {};
		var array = this.serializeArray();
		var str = this.serialize();
		$(array).each(
				function() {
					if (serializeObj[this.name]) {
						if ($.isArray(serializeObj[this.name])) {
							serializeObj[this.name].push(this.value);
						} else {
							serializeObj[this.name] = [
									serializeObj[this.name], this.value ];
						}
					} else {
						serializeObj[this.name] = this.value;
					}
				});
		return serializeObj;
	};
})(jQuery);
// “【“1”，“2”，“3”】” 这种字符串转为数组
function specialStringToArray(str) {
	// var s=str.replace(/\"/g,"'");
	var s = str.replace(/\"/g, "");
	s = s.substring(1, s.length - 1);

	var array = [];
	if (s.length > 0) {
		array = s.split(",");
	}
	return array;
}

function baseLoad(action, sessionKey) {
	var keyItem = getSessionValue(sessionKey);
	if (!keyItem) {
		var reqData = new RequestData(action);
		var jsonstr = JSON.stringify(reqData);
		$.ajax({
			cache : false,
			type : "POST",
			crossDomain : true,
			url : testUrl,
			data : jsonstr, // 你的formid
			async : false,
			error : function(request) {
				alert("Connection error");
			},
			success : function(data) {
				var dataObj = eval("(" + data + ")");
				if (dataObj.ret == 1) {
					if (dataObj.rows) {
						keyItem = JSON.stringify(dataObj.rows);
					} else if (dataObj.params) {
						keyItem = JSON.stringify(dataObj.params);
					}
					window.sessionStorage.setItem(sessionKey, keyItem);
				}
			}
		});
	}
	return keyItem;
}
function RequestData(url) {
	var timestamp = Math.round(new Date().getTime() / 1000);
	var obj = {
		relativeurl : url,
		caller : "chefuRegister",
		timestamp : timestamp,
		hashcode : $.md5("chefuRegistercheliao@2015" + timestamp)
	};
	return obj;
}

function UserObj(username, password) {
	this.username = username;
	this.password = password;
}
function getSessionValue(key) {
	var value = window.sessionStorage.getItem(key);
	if (value == 'undefined' || value == 'null') {
		value = null;
	}
	return value;
}
function transferFlagValue(value) {
	var v = "";
	if (value == 1 || value == "1") {
		v = "是";
	} else if (value == 0 || value == "0") {
		v = "否";
	}
	return v;
}
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null)
		return unescape(r[2]);
	return null;
}
function toPage(url) {
	location.href = url;
}

function popAlert(msg) {
	$('#my-alert').remove();
	var content = '<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">';
	content += '<div class="am-modal-dialog">  <div class="am-modal-hd"></div>';
	content += ' <div class="am-modal-bd">';
	content += msg;
	content += '</div><div class="am-modal-footer"><span class="am-modal-btn">确定</span> </div></div></div>';
	$('body').append(content);
	$('#my-alert').modal();

}
function popConfirm(title, msg, doConfirm) {
	$('#my-confirm').remove();
	var content = '<div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">';
	content += '  <div class="am-modal-dialog">';
	content += ' <div class="am-modal-hd">' + title + '</div>';
	content += '  <div class="am-modal-bd">' + msg + '</div>';
	content += '<div class="am-modal-footer">';
	content += ' <span class="am-modal-btn" data-am-modal-cancel>取消</span>';
	content += '<span class="am-modal-btn" data-am-modal-confirm>确定</span>';
	content += ' </div></div></div>';
	$('body').append(content);
	$('#my-confirm').modal({
		relatedTarget : this,
		onConfirm : doConfirm,
		onCancel : function() {

		}
	});
	// $('#my-popup').modal();
}
function Popup(title, msg) {
	$('#my-popup').remove();
	var content = '<div class="am-popup" id="my-popup">';
	content += ' <div class="am-popup-inner">';
	content += ' <div class="am-popup-hd">';
	content += ' <h4 class="am-popup-title">' + title + '</h4>';
	content += '  <span data-am-modal-close  class="am-close">&times;</span></div>';
	content += ' <div class="am-popup-bd">' + msg;
	content += ' </div></div></div>';
	$('body').append(content);
	$('#my-popup').modal();
}
function popLoading() {
	$('#my-modal-loading').remove();
	var content = '<div class="am-modal am-modal-loading am-modal-no-btn" tabindex="-1" id="my-modal-loading">';
	content += ' <div class="am-modal-dialog">';
	content += ' <div class="am-modal-hd">正在载入...</div>';
	content += ' <div class="am-modal-bd">';
	content += '  <span class="am-icon-spinner am-icon-spin"></span>';
	content += ' </div></div></div>';
	$('body').append(content);
	$('#my-modal-loading').modal();

}
function closeLoading() {
	$('#my-modal-loading').modal('close');
}
function doValidate(selector) {
	$(selector).validator(
			{
				onValid : function(validity) {
					$(validity.field).closest('.am-form-group').find(
							'.am-alert').hide();
					// userLogin();
				},
				onInValid : function(validity) {
					var $field = $(validity.field);
					var $group = $field.closest('.am-form-group');
					var $alert = $group.find('.am-alert');
					// 使用自定义的提示信息 或 插件内置的提示信息
					var msg = $field.data('validationMessage')
							|| this.getValidationMessage(validity);

					if (!$alert.length) {
						$alert = $(
								'<div class="am-alert am-alert-danger"></div>')
								.hide().appendTo($group);
					}

					$alert.html(msg).show();
				},
			});
}

function doFormValidate(selector) {
	var $form = $(selector);
	var $tooltip = $('<div id="vld-tooltip">提示信息！</div>');
	$tooltip.appendTo(document.body);

	$form.validator();

	var validator = $form.data('amui.validator');

	$form.on('focusin focusout', '.am-form-error input', function(e) {
		if (e.type === 'focusin') {
			var $this = $(this);
			var offset = $this.offset();
			var msg = $this.data('foolishMsg')
					|| validator.getValidationMessage($this.data('validity'));

			$tooltip.text(msg).show().css({
				left : offset.left + 10,
				top : offset.top + $(this).outerHeight() + 10
			});
		} else {
			$tooltip.hide();
		}
	});
}
/* 返回上一页 */
function backPrepage() {
	window.location.href = window.document.referrer;	
}
